/*
 * UseCaseIteratorFactory.java
 *

 */

package usecase;


/*import objectgen.usecase.IStep;
import objectgen.usecase.UseCaseXML;*/

import java.util.Iterator;
import org.apache.log4j.Logger;



/**
 * 
 */
public class UseCaseIteratorFactory 
{

	// Inner use constants
	private static final int TEMPLATE01 = 1;
	private static final int TEMPLATE02 = 2;
	
    
    /** This is a static class */
    private UseCaseIteratorFactory () {
    }
    
    
    /** Helpper method **/
    private static int TemplateType() {
    	String template;
    	template = configuration.Configuration.Get("Template");
        
        if (template == null) {
            log.warn ("Template property not found in config. file. Using template01");
            return TEMPLATE01;
        }
        
	if (template.compareTo("template02") == 0) 
		return TEMPLATE02;
	if (template.compareTo("template01") == 0)    														
		return TEMPLATE01;
	log.error("Template name >" + template 
				+ "< not found. Using template01" );
	return TEMPLATE01;
    }
    
    /**  **/
	public static Iterator GetIteratorPreevaluatedSteps(UseCaseXML uc,
						IStep s) {
		int templateType = TemplateType();
		if (templateType == TEMPLATE01) {
			if (s == null)
                            log.warn("You want an iterator to traverse preconditions" 
                                    + " of  a step but the step is null.");
                        log.debug ("Returning iterator for pre sequences (template01)");
			return uc.iteratorPreSequence (s);
		}
		if (templateType == TEMPLATE02) {
                        log.debug ("Returning iterator for alternative sequences (template02)");
			return uc.iteratorAlternativeSequence(s);
                }
		
		log.fatal("You must not be here");
		return null;
	}


	/* */
	public static Iterator GetIteratorPostevaluatedSteps(UseCaseXML uc,
							  IStep s) {
		int templateType = TemplateType();
		if (templateType == TEMPLATE01) {
			if (s == null)
				log.warn("You want an iterator to traverse postconditions"
				+ " of  a step but the step is null.");
			return uc.iteratorInvSequence (s);
		}
		if (templateType == TEMPLATE02)
			return uc.iteratorErrorSequence(s);
		
		log.fatal("You must not be here");
		return null;
		
	}
        
        
        /* */
	public static Iterator GetIteratorPostevaluatedStepsMethod(UseCaseXML uc,
							  IStep s) {		
			return uc.iteratorErrorMethodSequence(s);		
	}
        
        public static Iterator GetIteratorPreevaluatedStepsMethod(UseCaseXML uc,
							  IStep s) {		
			return uc.iteratorAlternativeMethodSequence(s);		
	}
        
        
        
        
	

	
    //--- Log ------------------------------------------------------------
    static Logger log;
    static {
        log = Logger.getLogger (UseCaseIteratorFactory.class.getName());
    } 

    
}
